# -*- coding: utf-8 -*-

from django import forms

class PaginationForm(forms.Form):
    search  = forms.CharField(required = False)
    offset  = forms.CharField(required = False)
    limit   = forms.CharField(required = False)
    sort    = forms.CharField(required = False)
    order   = forms.CharField(required = False)

    def getPaginationParams(self):
        '''
        返回分页参数
        '''
        try:
            params = {
                'limit': int(self.cleaned_data.get('limit', 20)),
                'offset': int(self.cleaned_data.get('offset', 0)),
                'sort': self.cleaned_data.get('sort', 'id'),
                'order': self.cleaned_data.get('order', 'asc'),
            }
            return params
        except Exception as e:
            print(e)
            return False
